package li.com.ruiji.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Slf4j
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("正在进行公共字段填充[添加]");
//        两个参数，字段名和需要填入的值
        metaObject.setValue("createTime", LocalDateTime.now());
        metaObject.setValue("updateTime", LocalDateTime.now());
        metaObject.setValue("createUser", MyBaseContext.getLongId());
        metaObject.setValue("updateUser", MyBaseContext.getLongId());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("正在进行公共字段填充[修改]");
        metaObject.setValue("updateTime", LocalDateTime.now());
        metaObject.setValue("updateUser", MyBaseContext.getLongId());
    }
}
